﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataControl;
using System.Data;
using System.Text;

namespace ATW.MT.BUS
{
    public class bus_Supply_Range
    {
        DataAccess da = null;
        public bus_Supply_Range()
        {
            da = new DataAccess();
        }
        #region 方法
        /// <summary>
        /// 供货范围申请分页
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="status">0未处理 1删除 2已处理</param>
        /// <param name="type">1新增 2删除</param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public DataTable SpRangePagerQuery(string userName, string status, string type, int page, int pagesize)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select au.tauName,
	                                   au.tauLoginId,
	                                   SR.content,
	                                   SR.SpRangeID,
	                                   SR.[type],
	                                   SR.rowstatus,
	                                   SR.create_time from T_SupplyRange SR 
                                left join  T_AppUser au on SR.tauloginid=au.tauLoginId where 1=1");
            if (userName != "")
            {
                sql.Append(" and au.tauname like '%" + userName + "%'");
            }
            if (type != "")
            {
                sql.Append(" and SR.[type]='" + type + "'");
            }
            if (status != "")
            {
                sql.Append(" and SR.rowstatus='" + status + "'");
            }
            return da.PageSize(sql.ToString(), page, pagesize, "SpRangeID", "create_time desc");
        }
        /// <summary>
        /// 供货范围申请查询
        /// </summary>
        /// <param name="SpRangeID"></param>
        /// <returns></returns>
        public DataTable SpRangeSingleQuery(string SpRangeID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select au.tauName,
	                                   au.tauLoginId,
	                                   SR.content,
	                                   SR.SpRangeID,
	                                   SR.[type],
	                                   SR.rowstatus,
	                                   SR.create_time from T_SupplyRange SR 
                                left join  T_AppUser au on SR.tauloginid=au.tauLoginId where SpRangeID='" + SpRangeID + "'");
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 更新状态
        /// </summary>
        /// <param name="SpRangeID"></param>
        /// <param name="rowstatus">0未处理 1已处理</param>
        /// <returns></returns>
        public int SpRangeUpdate(string SpRangeID, string rowstatus)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"update T_SupplyRange set rowstatus='" + rowstatus + "' where SpRangeID='" + SpRangeID + "'");
            return da.ExcuteNoQuery(sql.ToString());
        }
        #endregion
    }
}